#pragma once
#include "Common.hpp"
// #include "TurboAlloc.hpp"
#include "ObjectPool.hpp"

class PageCache
{
public:
    static PageCache *GetInstance()
    {
        return &_sInst;
    }
    // 获取从对象到span的映射
    Span *MapObjectToSpan(void *obj);
    // 释放空闲span到PageCache中 合并相邻的span
    void ReleaseSpanToPageCache(Span *span);
    // 获取一个K页的span
    Span *NewSpan(size_t k);
    std::mutex _pageMtx;

private:
    SpanList _spanLists[NPAGES];
    ObjectPool<Span> _spanPool;
    std::unordered_map<PAGE_ID, Span *> _idSpanMap;
    PageCache() {}
    PageCache(const PageCache &) = delete;
    static PageCache _sInst;
};